﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Authentication;
using System.Text;
using Newtonsoft.Json;

namespace OF.JsonRpc.Gateway
{
    public class TestAuthGateway : BaseAuthGateway
    {
        protected override void VerifyAuth(JsonRequest jsonRequest)
        {
            // 访问授权认证
            if (!jsonRequest.Tags.ContainsKey("auth_client_id") ||
                string.IsNullOrWhiteSpace(jsonRequest.Tags["auth_client_id"].ToString()))
            {
                throw new AuthenticationException("授权认证失败，缺少 auth_client_id 参数！");
            }
            if (!jsonRequest.Tags.ContainsKey("auth_token") ||
                string.IsNullOrWhiteSpace(jsonRequest.Tags["auth_token"].ToString()))
            {
                throw new AuthenticationException("授权认证失败，缺少 auth_token 参数！");
            }

            if (!this.Attributes["clientId"].Equals(jsonRequest.Tags["auth_client_id"]) 
                || !this.Attributes["token"].Equals(jsonRequest.Tags["auth_token"]))
            {
                throw new AuthenticationException("授权认证失败，密码错误！");
            }
        }
    }
}
